package com.itbaiwei.unitday01.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ScrollView;

/**
 * Class: CustomScrollView
 * Description:
 * Author: haijun.xu
 * Date: 2025/6/3 10:54
 */
public class CustomScrollView extends ScrollView {
    private float lastY=0;
    public CustomScrollView(Context context) {
        super(context);
    }
    public CustomScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
           super.onInterceptTouchEvent(ev);
        boolean intercept = false;
        ListView listView = (ListView)((ViewGroup) getChildAt(0)).getChildAt(1);
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                intercept=false;
                break;
            case MotionEvent.ACTION_MOVE:
                //listview划到顶部的时候，继续向下滑动，让scrollview拦截事件
                if(listView.getFirstVisiblePosition()==0&&(ev.getY()-lastY>0)){
                    System.out.println("滑动到头部");
                    intercept=true;
                    //如果listview滑动到底部，继续向上滑动,,
                }else if(listView.getLastVisiblePosition()==listView.getCount()-1&&(ev.getY()-lastY<0)){
                    System.out.println("滑动到底部");
                    intercept=true;
                }else{
                    System.out.println("其他条件");
                    intercept=false;
                }
                break;
            case MotionEvent.ACTION_UP:
                intercept=false;
                break;
        }
        lastY=ev.getY();
        return intercept;
    }





}
